package com.campus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.campus.domain.po.Course;
import com.campus.mapper.CourseMapper;
import com.campus.service.CourseService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

@Service
public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> implements CourseService {

    @Override
    public Course createCourse(Course course) {
        this.save(course);
        return course;
    }

    @Override
    public Course getCourseById(Integer id) {
        return this.getById(id);
    }

    @Override
    public Course updateCourse(Course course) {
        this.updateById(course);
        return this.getById(course.getId());
    }

    @Override
    public boolean deleteCourseById(Integer id) {
        return this.removeById(id);
    }

    @Override
    public Course getCourseByName(String courseName) {
        QueryWrapper<Course> wrapper = new QueryWrapper<>();
        wrapper.eq("course_name", courseName);
        return this.getOne(wrapper);
    }
}
